<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title>乐鲜生活-修改密码</title>
	<link rel="shortcut icon" href="favicon.ico" />
	<link rel="bookmark" href="favicon.ico" />
	<link rel="stylesheet" type="text/css" href="css/base.css" />
	<link rel="stylesheet" type="text/css" href="css/changepassword.css" />
	<link rel="stylesheet" type="text/css" href="css/asyncbox/asyncbox.css" />
	<style>
		.mmzT {
			margin-left: 10px;
			font-size: 15px;
		}
	</style>
</head>
<body>
	<div id="wrapper">
		<div id="header"></div>
		<div class="header distance_top">
			<div class="column_z">
				<ul>
					<li class="fist_li_z">个人中心</li>
					<li class="com_li com_li_color">
						<a href="index.html" class="icon_z_1">首页</a>
					</li>
				</ul>
				<div class="clr"></div>
				<div class="shopping_car">
					<a href="cart.html"> 我的购物车</a> <span class="tips2">0</span>
					<div class="shopping_car_list">
						<p class="first_paragraph"></p>
						<p class="second_paragraph">购物车中还没有商品，赶快选购吧！</p>
					</div>
				</div>
			</div>
		</div>
		<div class="main">
			<ul class="content_z_left">
				<li><a class="com_z">我的订单</a></li>
				<li><a href="unpaidorders.html">待付款订单</a></li>
				<li><a href="paidorders.html">待取货订单</a></li>
				<li><a class="com_z">账户设置</a></li>
				<li><a href="usersetting.html">个人信息</a></li>
				<li><a href="changepassword.html">修改密码</a></li>
				<li><a href="collections.html">我的收藏</a></li>
				<li><a class="com_z">我的钱包</a></li>
				<li><a href="charge.html">充值</a></li>
				<li><a href="transfer.html">转账</a></li>
				<li><a href="bills.html">账单</a></li>
			</ul>
			<div class="content_z_right padding_bottom_z_1">
				<div class="rightwrap">
					<h2>修改密码</h2>
					<div class="registerForm">
						<div>
							<span class="text"><span class="required"></span>旧密码：</span>
							<input type="password" placeholder="请输入旧密码" id="oldPassword" />
						</div>
						<div>
							<span class="text"><span class="required"></span>新密码：</span>
							<input type="password" id="password" placeholder="请输入新密码" />
						</div>
						<div class="clr"></div>
						<div>
							<span class="text"><span class="required"></span>确认新密码：</span>
							<input type="password" id="surepassword" placeholder="请再次输入新密码" />
						</div>
						<div class="clr"></div>
						<div class="clear">
							<span class="text" style="float: left">
								<span class="required" style="float: left"></span>
								验证码：
							</span>
							<input type="text" id="text1" placeholder="请输入验证码" style="float: left; width: 180px" />
							<input class="mmzT" id="validate" type="button"
								style="float: left; border: 1px solid #999; padding: 0 2px; background: #f2f2f2; width: 80px; height: 30px; font-size: 12px; text-align: center; color: #666; cursor: pointer"
								value="获取验证码" />
						</div>
						<div class="clr"></div>
						<div>
							<span class="text">&nbsp;</span>
							<a href='javascript:void(0);' class="submit" id="submit">确定</a>
						</div>
					</div>
				</div>
			</div>
			<div class="clr"></div>
		</div>
		<div id="footer"></div>
	</div>
	<script type="text/javascript" src="js/site/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="js/site/AsyncBox.v1.4.js"></script>
	<script type="text/javascript" src="js/site/validate.js"></script>
	<script type="text/javascript" src="js/site/common.js"></script>
	<script type="text/javascript">
		var phone;
		$(function() {
			if (!util.isLogin()) {
				window.location = "login.html";
			}
			findShopCarCount();
			$("#submit").click(function() {
				var password = $.trim($("#password").val());
				var oldPassword = $.trim($("#oldPassword").val());
				var surepassword = $.trim($("#surepassword").val());
				var code = $.trim($("#text1").val());
				if (!validateUtil.validateEmpty(oldPassword)) {
					asyncbox.tips("旧密码不能为空！", asyncbox.Level.error);
					return;
				}
				// 校验新密码是否为空 
				if (!validateUtil.validateEmpty(password)) {
					asyncbox.tips("请输入新密码！", asyncbox.Level.error);
					return;
				}
				if (oldPassword == password) {
					asyncbox.tips("新密码与旧密码不能相同！", asyncbox.Level.error);
					return;
				}
				// 校验新密码格式
				if (!validateUtil.validatePassword(password)) {
					asyncbox.tips("密码由数字或字母组成！", asyncbox.Level.error);
					return;
				}
				//  校验长度
				if (!validateUtil.validateLength(password, 6, 16)) {
					asyncbox.tips("请输入6-16位有效新密码！", asyncbox.Level.error);
					return;
				}
				// 校验密码是否为空
				if (!validateUtil.validateEmpty(surepassword)) {
					asyncbox.tips("请输入确认密码！", asyncbox.Level.error);
					return;
				}
				// 校验两次密码是否一致
				if (password != surepassword) {
					asyncbox.tips("两次密码不一致，请重新输入！", asyncbox.Level.error);
					return;
				}
	
				var data = {
					password : password,
					oldPassword : oldPassword,
					code : code,
					phone : phone
				};
	
				$.postAjax("/user/changeoPassword.do", data, function(json) {
					if (json.code) {
						asyncbox.tips(json.message, asyncbox.Level.error);
						return;
					}
					asyncbox.tips('修改密码成功', asyncbox.Level.success);
					$.postAjax("/user/logout.do", {}, function(json) {
						if (json.code) {
							return;
						}
						setTimeout(function() {
							window.location = "login.html";
						}, 3000)
					}, function() {
					});
				}, function() {
					asyncbox.tips("网络连接错误", asyncbox.Level.error);
					return;
				});
			});
	
			var countdown = 60;
			function settime(obj) {
				if (countdown == 0) {
					$(obj).attr("disabled", false);
					$(obj).attr("value", "发送验证码");
					$(obj).css("cursor", "");
					countdown = 60;
				} else {
					$(obj).attr("disabled", true);
					$(obj).css("cursor", "default");
					$(obj).attr("value", countdown + "s");
					countdown--;
					setTimeout(function() {
						settime(obj);
					}, 1000);
				}
			}
			$("#validate").click(
				function() {
					var count = 60;
					phone = phone;
					var param = {
						type : 3,
						platformCode : 2
					};
					$.postAjax("/validation/getValidateCode.do", param,
						function(json) {
							if (json.code) {
								asyncbox.tips(json.message, asyncbox.Level.error);
								return;
							}
							var obj = $("#validate");
							settime(obj);
						}
					);
				}
			);
		});
	
		function findShopCarCount() {
			$.postAjax("/commodity/getTrolleyCount.do", {}, function(json) {
				if (json.code) {
					asyncbox.tips(json.message, asyncbox.Level.error);
					return;
				}
				var count = eval("(" + json.data + ")")
				$(".shopping_car>span[class='tips2']").text(count);
			}, function() {
			});
		}
	</script>
</body>
</html>